package com.example.leetcode.demo.leetcode;

public class twoSum {
    public static void main(String[] args) {
        int [] nums=new int[]{5,25,75};
        twoSum twoSun=new twoSum();
        int[] a=twoSun.twoSum(nums,100);
        for(int k=0;k<a.length;k++){
            System.out.print(a[k]);
        }
    }

    public int[] twoSum(int[] numbers,int target){
        int left=0,right=numbers.length-1;
        while(left<=right){
            if(numbers[left]+numbers[right]==target){
                return new int[]{left+1,right+1};
            }else if(numbers[left]+numbers[right]>target){
                right--;
            }else if(numbers[left]+numbers[right]<target){
                left++;
            }
        }
        return new int[]{-1,-1};
    }
    /*
    public int[] twoSum(int[] numbers,int target){
        for(int i=0;i<numbers.length;i++){
            for (int j=i+1;j<numbers.length;j++){
                if(numbers[i]+numbers[j]==target){
                    return new int[]{i+1,j+1};
                }
            }
        }
        return new int[]{-1,-1};
    }
     */

}
